// 函数防抖

// 

function debounce (fn,duration){
  var timer = null

    return function(){
       clearTimeout(timer)
       var curThis = this
       // 将该函数的参数全部传递给fn
       // 假如传入数组
       console.log(arguments)
       var args = Array.prototype.slice.call(arguments,0)
       console.log(args)
       timer = setTimeout(function(){
        fn.apply(curThis,args)
      },duration)
    }
    
}
// 节流
function throttle (fn,duration){
  var timer = null

    return function(){
      //  clearTimeout(timer)
       if(timer){
        return
       }
       var curThis = this
       // 将该函数的参数全部传递给fn
       // 假如传入数组
       console.log(arguments)
       var args = Array.prototype.slice.call(arguments,0)
       console.log(args)
       timer = setTimeout(function(){
        fn.apply(curThis,args)
      },duration)
    }
    
}
var handle = throttle(function(arr){
  console.log('我执行了',arr)
  document.write('我触发了')
},1000)

var btn = document.querySelector('button')
btn.onclick = function(){
  handle([1,2,3,4])
}